<?php

/**
 * Test: Nette\Config\ConfigAdapterIni
 *
 * @author     David Grudl
 * @package    Nette\Config
 * @subpackage UnitTests
 */

use Nette\Config\Config;



require __DIR__ . '/../bootstrap.php';

define('TEMP_FILE', __DIR__ . '/tmp/cfg.ini');


// Load INI
$config = Config::fromFile('config1.ini');
Assert::same( array(
	'production' => array(
		'webname' => 'the example',
		'database' => array(
			'params' => array(
				'host' => 'db.example.com',
				'username' => 'dbuser',
				'password' => 'secret',
				'dbname' => 'dbname',
			),
			'adapter' => 'pdo_mysql',
		),
	),
	'development' => array(
		'database' => array(
			'params' => array(
				'host' => 'dev.example.com',
				'username' => 'devuser',
				'password' => 'devsecret',
				'dbname' => 'dbname',
			),
			'adapter' => 'pdo_mysql',
		),
		'timeout' => '10',
		'display_errors' => '1',
		'html_errors' => '',
		'items' => array(
			'10',
			'20',
		),
		'webname' => 'the example',
	),
), $config->toArray() );



// Save INI
$config->save(TEMP_FILE);
Assert::match( <<<EOD
; generated by Nette

[production]
webname = "the example"
database.params.host = "db.example.com"
database.params.username = "dbuser"
database.params.password = "secret"
database.params.dbname = "dbname"
database.adapter = "pdo_mysql"

[development]
database.params.host = "dev.example.com"
database.params.username = "devuser"
database.params.password = "devsecret"
database.params.dbname = "dbname"
database.adapter = "pdo_mysql"
timeout = 10
display_errors = 1
html_errors = ""
items.0 = 10
items.1 = 20
webname = "the example"
EOD
, file_get_contents(TEMP_FILE) );



// Save section to INI
$config->save(TEMP_FILE, 'mysection');
Assert::match( <<<EOD
; generated by Nette

[mysection]
production.webname = "the example"
production.database.params.host = "db.example.com"
production.database.params.username = "dbuser"
production.database.params.password = "secret"
production.database.params.dbname = "dbname"
production.database.adapter = "pdo_mysql"
development.database.params.host = "dev.example.com"
development.database.params.username = "devuser"
development.database.params.password = "devsecret"
development.database.params.dbname = "dbname"
development.database.adapter = "pdo_mysql"
development.timeout = 10
development.display_errors = 1
development.html_errors = ""
development.items.0 = 10
development.items.1 = 20
development.webname = "the example"
EOD
, file_get_contents(TEMP_FILE) );
